import { getStream } from '../Core/connect'
import * as MathUtils from '../Math/MathUtils'

export class WMSServer {
    readonly type: string
    name: string
    url: string
    index: number
    uuid: string
    constructor(option: WMSOption) {
        this.type = 'WMSServer'
        this.name = option.name
        this.url = option.url
        this.index = option.index
        this.uuid = MathUtils.generateUUID()
        this.init()
    }
    init() {
        const stream = getStream()
        const str = {gisFunction: 'addWMSLayer', ids: `${this.type},${this.name},${this.uuid}`, url:`${this.url}`, name:`${this.name}`, index:`${this.index}`}
        stream.emitUIInteraction(str)
    }
    setLayerURL(url: string) {
        this.url = url
        const stream = getStream()
        const str = {gisFunction: 'setWMSURL', ids: `${this.uuid}`, url:`${this.url}`}
        stream.emitUIInteraction(str)
    }
    setLayerIndex(index: number) {
        this.index = index
        const stream = getStream()
        const str = {gisFunction: 'setLayerIndex', ids: `${this.uuid}`, index:`${this.index}`}
        stream.emitUIInteraction(str)
    }
    setLayerName(name: string) {
        this.name = name
        const stream = getStream()
        const str = {gisFunction: 'setLayerName', ids: `${this.uuid}`, name:`${this.name}`}
        stream.emitUIInteraction(str)
    }
    removeLayer() {
        const stream = getStream()
        const str = {gisFunction: 'removeLayer', ids: `${this.uuid}`}
        stream.emitUIInteraction(str)
    }
}